package ru.mcfr.oxygen.framework.extensions;

import ro.sync.ecss.extensions.api.AuthorAccess;
import ro.sync.ecss.extensions.api.node.AuthorNode;
import ro.sync.ecss.extensions.api.structure.AuthorBreadCrumbCustomizer;
import ro.sync.ecss.extensions.api.structure.RenderingInformation;

import javax.swing.*;

public class MOFAuthorBreadCrumbCustomizer extends AuthorBreadCrumbCustomizer {

    public void customizeRenderingInformation(RenderingInformation renderInfo) {
        // Get the node to be rendered
        AuthorNode node = renderInfo.getNode();

        String name = node.getName();
        if (name.length() > 0) {
            if ("para".equals(name)) {
                name = "Paragraph";
            } else {
                // Capitalize the first letter
                name = name.substring(0, 1).toUpperCase() + name.substring(1, name.length());
            }
        }

        // Set the render text
        renderInfo.setRenderedText("[" + name + "]");
    }

    public void customizePopUpMenu(Object popUp, AuthorAccess authorAccess) {
        if (popUp instanceof JPopupMenu) {
            JPopupMenu popupMenu = (JPopupMenu) popUp;
            // Remove all the components from the popUp menu .
            popupMenu.removeAll();
        }
    }
}
